package com.atguigu.tingshu.user.strategy.impl;

import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.user.strategy.PaymentStrategy;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author atguigu-mqx
 * @ClassName AlbumPaymentStrategy
 * @description: TODO
 * @date 2024年06月26日
 * @version: 1.0
 */
@Service("1001")
public class AlbumPaymentStrategy implements PaymentStrategy {

    @Autowired
    private UserPaidAlbumMapper userPaidAlbumMapper;

    /**
     * 购买专辑记录
     * @param userPaidRecordVo
     */
    @Override
    public void processPayment(UserPaidRecordVo userPaidRecordVo) {
        //  根据订单编号查询是否有当前订单 select * from user_paid_album where order_no = ? ;
        UserPaidAlbum userPaidAlbumQuery = userPaidAlbumMapper.selectOne(new LambdaQueryWrapper<UserPaidAlbum>().eq(UserPaidAlbum::getOrderNo, userPaidRecordVo.getOrderNo()));
        if (userPaidAlbumQuery != null) return;
        //  购买专辑  user_paid_album
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        //  给属性赋值：
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbumMapper.insert(userPaidAlbum);
    }
}
